<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
<script>

function MyNew (fn, ...args) {
    // 1.
    // let context = Object.create(fn.prototype)
    // context.fn = fn
    // context.fn(...args)
    // delete context.fn


    // 2.
    let context = {}
    fn.call(context, ...args)
    context.__proto__ = fn.prototype

    return context
}

function Person (name, age) {
    this.name = name
    this.age = age
}
Person.prototype.say = function () {
    console.log('say my name:', this.name)
}

let p1 = new Person('p1', 22)
console.log('p1:', p1)
p1.say()

let p2 = MyNew(Person, 'p2', 24)
console.log('p2:', p2)
p2.say()

</script>
</body>
</html>